package com.gagakuai.engine.impl.pvm.runtime;


import com.gagakuai.engine.exception.PvmException;
import com.gagakuai.engine.impl.delegate.ActivityBehavior;
import com.gagakuai.engine.impl.pvm.process.ActivityImpl;
import com.gagakuai.engine.impl.pvm.runtime.AtomicOperation;
import com.gagakuai.engine.impl.runtime.InterpretableExecution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * @program: common-starters
 * @description: 活动实列执行
 * @author: houhong
 * @create: 2023-01-02 20:06
 */
public class AtomicOperationActivityExecute implements AtomicOperation {

    private static final Logger LOGGER = LoggerFactory.getLogger(AtomicOperationActivityExecute.class);


    @Override
    public void execute(InterpretableExecution execution) {
        //从执行中获取到当前活动
        ActivityImpl activity = (ActivityImpl) execution.getActivity();
        //获取到当前活动到行为类
        ActivityBehavior activityBehavior = activity.getActivityBehavior();

        if (activityBehavior == null) {
            throw new PvmException("no behavior specified in " + activity);
        }

        LOGGER.debug("{} executes {}: {}", execution, activity, activityBehavior.getClass().getName());

        //// TODO: 2023/4/30  事件转发器


        //执行活动的行为类,由行为类决定不同的业务
        activityBehavior.execute(execution);
    }

    @Override
    public Boolean isAsync(InterpretableExecution execution) {
        return false;
    }
}